﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace ShevaEngine.Core.Modules.Graphics
{
    /// <summary>
    /// Draw call manager.
    /// </summary>
    public class DrawCallManager
    {
        /// <summary>Singleton.</summary>
        public static readonly DrawCallManager Instance = new DrawCallManager();

        /// <summary>Indexed primitives draw calls.</summary>
        private Dictionary<IndexedPrimitivesDrawCall, IndexedPrimitivesDrawCall> IndexedPrimitivesDrawCalls;
        

        /// <summary>
        /// Constructor.
        /// </summary>
        internal DrawCallManager()
        {
            this.IndexedPrimitivesDrawCalls = new Dictionary<IndexedPrimitivesDrawCall, IndexedPrimitivesDrawCall>(
                new IndexedPrimitivesDrawCallEqualityComparer());
        }

        /// <summary>
        /// Method creates new Indexed primitive draw call.
        /// </summary>
        /// <param name="primitiveType"></param>
        /// <param name="numVertices"></param>
        /// <param name="primitiveCount"></param>
        /// <param name="startIndex"></param>
        /// <param name="vertexOffset"></param>
        /// <param name="baseVertex"></param>
        /// <returns></returns>
        public IndexedPrimitivesDrawCall CreateIndexedPrimitivesDrawCall(
            PrimitiveType primitiveType, Int32 numVertices, Int32 primitiveCount, Int32 startIndex, Int32 vertexOffset, Int32 baseVertex)
        {
            IndexedPrimitivesDrawCall newDrawCall = new IndexedPrimitivesDrawCall(primitiveType, numVertices,
                primitiveCount, startIndex, vertexOffset, baseVertex);

            if (!this.IndexedPrimitivesDrawCalls.ContainsKey(newDrawCall))
                this.IndexedPrimitivesDrawCalls.Add(newDrawCall, newDrawCall);
            else
            { }

            return this.IndexedPrimitivesDrawCalls[newDrawCall];
        }
    }
}
